package org.ws.lifebacklog.util;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Used for update UI elements such as set text to {@link TextView} or image for {@link ImageView} with id validation.
 * 
 * @author sergey.valuy
 * */
public class UIUtil {
	public static void setText(View view, int resId, int textId) {
		if (view != null && view.findViewById(resId) instanceof TextView && textId > 0) {
			((TextView) view.findViewById(resId)).setText(textId);
			view.forceLayout();
			view.invalidate();
		} else {
			Logger.e(UIUtil.class, String.format("Can't set  text with id %d to  view %d", textId, resId));
		}
	}

	public static void setText(View view, int resId, String text) {
		if (view != null && view.findViewById(resId) instanceof TextView) {
			((TextView) view.findViewById(resId)).setText(text);
			view.invalidate();
		}
	}
}
